package demo.practice.double_pointer;

public class P392 {

    public boolean isSubsequence2(String s, String t) {
        if (s.length() == 0) {
            return true;
        }
        char[] chars = s.toCharArray();
        char[] chart = t.toCharArray();
        int j = 0;
        for (int i = 0; i < chart.length; i++) {
            if (chars[j] == chart[i]) {
                j++;
                if (j == chars.length) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isSubsequence(String s, String t) {
        if (s == null || s.length() == 0)
            return true;

        int i = 0, j = 0;
        while (j < t.length()) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
                j++;
            } else {
                j++;
            }
            if (i == s.length())
                return true;
        }

        return false;
    }
}
